
# Table of Contents

1.  [bootstrap use-package](#orgdef9c50)
2.  [packages](#orgf67a5ee)
    1.  [avy](#orgb08f70c)
    2.  [markdown](#org523a777)
    3.  [deft](#org49e7577)
3.  [Some custom stuff](#org21c1317)
    1.  [custom.el](#orge441e8b)
    2.  [some ui toggles](#orgf76d9d8)
    3.  [don't let emacs litter](#org8de8100)
    4.  [ido](#org5879ede)
4.  [some little useful functions](#orgf1b8469)
5.  [blogging](#org9e9a9e7)
6.  [key bindings](#org50cac6d)



<a id="orgdef9c50"></a>

# bootstrap use-package

Add melpa to the package manager, install use-package. You don't have to use [use-package](https://github.com/jwiegley/use-package) but it does make everything nice and clean and smooth. You can also use [straight.el](https://github.com/raxod502/straight.el) as a package manager *(use-package is not a package manager)* and I may do that at some point, but for right now this is working.

    (require 'package)
    ;; Any add to list for package-archives (to add marmalade or melpa) goes here
    (add-to-list 'package-archives 
    	     '("MELPA" .
    	       "http://melpa.milkbox.net/packages/"))
    (package-initialize)
    
    
    (unless (package-installed-p 'use-package)
      (package-refresh-contents)
      (package-install 'use-package))
    (eval-when-compile
      (require 'use-package))
    (setq use-package-always-ensure t)


<a id="orgf67a5ee"></a>

# packages

Much like vim, emacs has a vibrant community of developers who have extended emacs into the swiss army knife that it is. Lots of that consists of emacs lisp packages like the three or four I am using here. 


<a id="orgb08f70c"></a>

## avy

For me, evil-mode is just too much. I could use viper mode *(I kinda like that vim style of motion)* but I really like emacs key bindings. To me they make sense and work for me. **But** yeah, sometimes you wanna just cut to the chase and get where you are going quick. [avy](https://github.com/abo-abo/avy) lets me do that. 

    ;; avy is a GNU Emacs package for jumping to visible text using a char-based decision tree.
    ;; https://github.com/abo-abo/avy/tree/3bf83140fad4c28f2dc4c7107b9d8fef84d17cb9
    (use-package avy
      :ensure t
      :commands (avy-goto-word-0
    	     avy-goto-line
    	     avy-resume
    	     avy-copy-line
    	     avy-copy-region)
      :bind (("C-c a g w" . #'avy-goto-word-0)
    	 ("C-c a g s" . #'avy-goto-subword-0)
    	 ("C-c a g c" . #'avy-goto-char-timer)
    	 ("C-c a g l" . #'avy-goto-line)
    	 ("C-c a c l" . #'avy-copy-line)
    	 ("C-c a c r" . #'avy-copy-region)
    	 ("C-c a C-j" . #'avy-resume)
    	 ("C-c a s l" . #'avy-kill-ring-save-whole-line)
    	 ("C-c a s r" . #'avy-kill-ring-save-region)
    	 ("C-c a m l" . #'avy-move-line)
    	 ("C-c a m r" . #'avy-move-region)
    	 ("M-g c"     . #'avy-goto-char)
    	 ("M-g l"     . #'avy-goto-line)
    	 ("M-g w"     . #'avy-goto-word-1)
    	 ("M-z"       . #'avy-zap-to-char-dwim)
    	 :map isearch-mode-map
    	 ("C-'" . #'avy-isearch)))
    
    (use-package avy-zap
      :ensure t
      :commands (avy-zap-to-char-dwim
    	     avy-zap-up-to-char-dwim)
      :bind (("C-c a z t" . #'avy-zap-to-char-dwim)
    	 ("C-c a z u" . #'avy-zap-up-to-char-dwim)))


<a id="org523a777"></a>

## markdown

You need markdown-mode! Everything runs on markdown.

    (use-package auto-org-md)
    
    (use-package markdown-mode
      :ensure t
      :mode (("README\\.md\\'" . gfm-mode)
    	 ("\\.md\\'" . markdown-mode)
    	 ("\\.markdown\\'" . markdown-mode))
      :init (setq markdown-command "multimarkdown"))


<a id="org49e7577"></a>

## deft

You don't exactly *need* [deft](https://jblevins.org/projects/deft/), but boy is it nice. I depend on it for my personal system and couldn't imagine working without it.

    (use-package deft
      :defer t
      :delight (deft-mode "D")
      :commands (deft)
      :config (setq deft-directory "~/documents"
    		deft-extensions '("org" "md")
    		deft-default-extension "org"
    		deft-text-mode 'org-mode))


<a id="org21c1317"></a>

# Some custom stuff


<a id="orge441e8b"></a>

## custom.el

I don't like my init.el being cluttered up with emacs droppings so this ensures that those emacs droppings are hitting the right newspaper

    (setq custom-file "~/.emacs.d/custom.el")
    (unless (file-exists-p custom-file)
      (write-region "" nil custom-file))
    ;;; Load custom file. Don't hide errors. Hide success message
    (load custom-file nil t)


<a id="orgf76d9d8"></a>

## some ui toggles

Yeah, I don't like all the emacs defaults. Nobody does. 

    (menu-bar-mode -1) ;; don't need the menu bar especially in terminal
    (load-theme 'wombat) ;; but you want some color
    (defalias 'yes-or-no-p 'y-or-n-p) ;; change yes or no to y or n
    (show-paren-mode 1) ;; show matching parens


<a id="org8de8100"></a>

## don't let emacs litter

Emacs creates backups and lockfiles. Backups are nice because they can get you out of a jam, but lockfiles aren't all that useful to me.

    (defvar --backup-directory (concat user-emacs-directory "backups"))
    (if (not (file-exists-p --backup-directory))
        (make-directory --backup-directory t))
    (setq backup-directory-alist `(("." . ,--backup-directory)))
    (setq make-backup-files t               ; backup of a file the first time it is saved.
          backup-by-copying t               ; don't clobber symlinks
          version-control t                 ; version numbers for backup files
          delete-old-versions t             ; delete excess backup files silently
          delete-by-moving-to-trash t
          create-lockfiles nil		; don't litter the system with lockfiles
          kept-old-versions 6               ; oldest versions to keep when a new numbered backup is made (default: 2)
          kept-new-versions 9               ; newest versions to keep when a new numbered backup is made (default: 2)
          auto-save-default t               ; auto-save every buffer that visits a file
          auto-save-timeout 20              ; number of seconds idle time before auto-save (default: 30)
          auto-save-interval 200            ; number of keystrokes between auto-saves (default: 300)
          )


<a id="org5879ede"></a>

## ido

Ido replaces the builtin and is much nice because it gives you better feedback.

    (setq ido-enable-flex-matching t)
    (setq ido-everywhere t)
    (setq ido-use-filename-at-point 'guess)
    (setq ido-create-new-buffer 'always)
    (setq ido-file-extensions-order '(".org" ".md" ".txt" ".py" ".emacs" ".xml" ".el" ".ini" ".cfg" ".cnf"))
    (setq linum-format "%4d ")
    (ido-mode 1)


<a id="orgf1b8469"></a>

# some little useful functions

I don't *need* these but it is handy to have them.

    (defun tilde/prog-mode-hook ()
      (linum-mode t))
    
    (defun tilde/reload-init ()
      (interactive)
      (load-file "~/.emacs.d/init.el"))
    
    (defun tilde/find-init ()
      (interactive)
      (find-file (concat user-emacs-directory "/init.el")))
    
    (add-hook 'prog-mode-hook #'tilde/prog-mode-hook)                            


<a id="org9e9a9e7"></a>

# blogging

On tilde.team I use bb to post to my blog. I can 100% promise you that there is a better way to do this, but this was quick and works.

    (defvar bb-bin "~/.local/bin/bb")
    (defvar bb-post "post " "bb post action")
    (defvar bb-edit "edit ")
    (defvar bb-delete "delete ")
    (defvar bb-rebuild "rebuild ")
    (defvar bb-reset "reset ")
    (defvar bb-list "list ")
    (defvar bb-tags "tags ")
    (defvar bb-html "-html " "Force bb to use html rather than markdown")
    (defvar bb-rename-or-list-all-tags-n "-n ")
    (defvar bb-use-full-html-f "-f ")
    
    (defun bash-blog (&optional action  flags filename)
      "BashBlog wrapper "
      (async-shell-command (concat bb-bin " " action flags filename) "*Bash-Blog Output*" "*Bash-Blog Error*")
      )
    
    (defun show-file-name ()
      "Show the full path file name in the minibuffer."
      (interactive)
      (message (buffer-file-name))
      (kill-new (file-truename buffer-file-name))
      )
    
    (defun post-markdown-to-bash-blog ()
      "Let bash-blog do all the work, just don't edit the file. Why isn't this an option?"
      (interactive)
      (bash-blog bb-post nil (buffer-file-name))
      (switch-to-buffer "*Bash-Blog Output*"))


<a id="org50cac6d"></a>

# key bindings

Most of my key bindings are here. Maybe some are scattered around, but I will fix that as I go.
Some are for convenience, but some are needed because when I log in to tilde.team I use the defaul setup which is tmux. Tmux grabs **C-a** so I've replaced that binding with **M-a** not the best but it works.

    (global-set-key (kbd "C-x C-b") #'ibuffer) ; rebind with ibuffer
    (global-set-key (kbd "M-,") #'beginning-of-buffer)
    (global-set-key (kbd "M-.") #'end-of-buffer)
    (global-set-key (kbd "C-c f r") #'tilde/reload-init)
    (global-set-key (kbd "C-c f i") #'tilde/find-init)
    (global-set-key (kbd "M-/") #'hippie-expand)
    (global-set-key (kbd "M-a") #'beginning-of-visual-line)
    (global-set-key (kbd "M-e") #'end-of-visual-line)
    (global-set-key (kbd "C-c t r") #'ruler-mode)
    (global-set-key (kbd "C-c p m") #'post-markdown-to-bash-blog)
    (global-set-key (kbd "C-c z") 'show-file-name)
    (global-set-key (kbd "C-c d") #'deft)

